home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / mail / pine3.96.tar.gz / pine3.96.tar / pine3.96 / pine / osdep / debuging.os2 < prev    next >
Text File  |  1996-03-14  |  3KB  |  110 lines

  1. #line 2 "osdep/debuging.os2"
  2. #ifdef DEBUG
  3. /*----------------------------------------------------------------------
  4.      Initialize debugging - open the debug log file
  5.  
  6.   Args: none
  7.  
  8.  Result: opens the debug logfile for dprints
  9.   ----*/
  10. void
  11. init_debug()
  12. {
  13.     char *p;
  14.     char filename[MAXPATH+1];
  15.  
  16.     if(!debug)
  17.       return;
  18.  
  19.     /*
  20.      * we can't assume anything about root or home dirs, so
  21.      * just plunk it down in the same place as the pinerc
  22.      */
  23.     
  24.     if(ps_global->pinerc)
  25.       sprintf(filename, "%.*s%s",
  26.           last_cmpnt(ps_global->pinerc) - ps_global->pinerc,
  27.           ps_global->pinerc, DEBUGFILE);
  28.     else if((p=getenv("PINEHOME"))!=NULL || (p=getenv("HOME"))!=NULL)
  29.       build_path(filename, p, DEBUGFILE);
  30.     else
  31.       strcpy(filename, DEBUGFILE);
  32.  
  33.     unlink(filename);
  34.  
  35.     debugfile = fopen(filename, "w");
  36.     if(debugfile != NULL){
  37.     time_t now = time((time_t *)0);
  38.     if(debug > 7)
  39.       setbuf(debugfile, NULL);
  40.     dprint(1, (debugfile, "Debug output of the Pine program (at debug"));
  41.     dprint(1, (debugfile, " level %d).  Version %s\n%s\n",
  42.           debug, pine_version, ctime(&now)));
  43.     }
  44. }
  45.  
  46.  
  47. void
  48. save_debug_on_crash(dfile)
  49. FILE *dfile;
  50. {
  51.     char *crashname = CRASHFILE;
  52.     char *filename = DEBUGFILE;
  53.     int status;
  54.     char msg[256];
  55.     time_t now = time((time_t *)0);
  56.  
  57.     fprintf(dfile, "\nsave_debug_on_crash: Version %s: debug level %d\n",
  58.     pine_version, debug);
  59.     fprintf(dfile, "\n                   : %s\n", ctime(&now));
  60.     fprintf(dfile, "\nAttempting to save debug file to %s\n", crashname);
  61.  
  62.     fclose(dfile);
  63.  
  64.     unlink (crashname);
  65.     status = rename (filename, crashname);
  66.  
  67. #ifdef _WINDOWS
  68.     sprintf (msg, "Pine debugging information saved in file:  %s",
  69.         status == 0 ? crashname : filename);
  70.     mswin_messagebox (msg);
  71. #endif
  72. }
  73.  
  74.  
  75. #define CHECK_EVERY_N_TIMES 100
  76. #define MAX_DEBUG_FILE_SIZE 200000L
  77. /*
  78.  * This is just to catch runaway Pines that are looping spewing out
  79.  * debugging (and filling up a file system).  The stop doesn't have to be
  80.  * at all precise, just soon enough to hopefully prevent filling the
  81.  * file system.  If the debugging level is high (9 for now), then we're
  82.  * presumably looking for some problem, so don't truncate.
  83.  */
  84. int
  85. do_debug(debug_fp)
  86. FILE *debug_fp;
  87. {
  88.     static int counter = CHECK_EVERY_N_TIMES;
  89.     static int ok = 1;
  90.     long filesize;
  91.  
  92.     if(debug < 9 && ok && --counter <= 0){
  93.     if((filesize = fp_file_size(debug_fp)) != -1L)
  94.       ok = (unsigned long)filesize < (unsigned long)MAX_DEBUG_FILE_SIZE;
  95.  
  96.     counter = CHECK_EVERY_N_TIMES;
  97.     if(!ok){
  98.         fprintf(debug_fp, "\n\n --- No more debugging ---\n");
  99.         fprintf(debug_fp,
  100.         "     (debug file growing too large - over %ld bytes)\n\n",
  101.         MAX_DEBUG_FILE_SIZE);
  102.         fflush(debug_fp);
  103.     }
  104.     }
  105.     return(ok);
  106. }
  107. #endif /* DEBUG */
  108.  
  109.  
  110.